/*********************************************

				DROP DE TABLAS

**********************************************/

--DROP DE FOREIGN KEYS

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Calificaciones_Usuarios]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Calificaciones]'))
ALTER TABLE [Monkey_Coders].[Calificaciones] DROP CONSTRAINT [FK_Calificaciones_Usuarios]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Calificaciones_Vendedores]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Calificaciones]'))
ALTER TABLE [Monkey_Coders].[Calificaciones] DROP CONSTRAINT [FK_Calificaciones_Vendedores]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_cli_usuario_id]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Clientes]'))
ALTER TABLE [Monkey_Coders].[Clientes] DROP CONSTRAINT [FK_cli_usuario_id]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__Clientes__cli_te__60D30FEF]') AND type = 'D')
BEGIN
ALTER TABLE [Monkey_Coders].[Clientes] DROP CONSTRAINT [DF__Clientes__cli_te__60D30FEF]
END

GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Compras_Ofertas_subasta]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Compras]'))
ALTER TABLE [Monkey_Coders].[Compras] DROP CONSTRAINT [FK_Compras_Ofertas_subasta]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Compras_Publicaciones]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Compras]'))
ALTER TABLE [Monkey_Coders].[Compras] DROP CONSTRAINT [FK_Compras_Publicaciones]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_emp_usuario_id]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Empresas]'))
ALTER TABLE [Monkey_Coders].[Empresas] DROP CONSTRAINT [FK_emp_usuario_id]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__Empresas__emp_te__63AF7C9A]') AND type = 'D')
BEGIN
ALTER TABLE [Monkey_Coders].[Empresas] DROP CONSTRAINT [DF__Empresas__emp_te__63AF7C9A]
END
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Facturas_Usuarios]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Facturas]'))
ALTER TABLE [Monkey_Coders].[Facturas] DROP CONSTRAINT [FK_Facturas_Usuarios]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Item_factura_Facturas]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Item_factura]'))
ALTER TABLE [Monkey_Coders].[Item_factura] DROP CONSTRAINT [FK_Item_factura_Facturas]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Item_factura_Publicaciones]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Item_factura]'))
ALTER TABLE [Monkey_Coders].[Item_factura] DROP CONSTRAINT [FK_Item_factura_Publicaciones]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Ofertas_subasta_Subastas]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Ofertas_subasta]'))
ALTER TABLE [Monkey_Coders].[Ofertas_subasta] DROP CONSTRAINT [FK_Ofertas_subasta_Subastas]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Preguntas_Publicaciones]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Preguntas]'))
ALTER TABLE [Monkey_Coders].[Preguntas] DROP CONSTRAINT [FK_Preguntas_Publicaciones]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Preguntas_Usuarios]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Preguntas]'))
ALTER TABLE [Monkey_Coders].[Preguntas] DROP CONSTRAINT [FK_Preguntas_Usuarios]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Publicaciones_Estados_publicaciones]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Publicaciones]'))
ALTER TABLE [Monkey_Coders].[Publicaciones] DROP CONSTRAINT [FK_Publicaciones_Estados_publicaciones]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Publicaciones_Usuarios]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Publicaciones]'))
ALTER TABLE [Monkey_Coders].[Publicaciones] DROP CONSTRAINT [FK_Publicaciones_Usuarios]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Publicaciones_Visibilidades]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Publicaciones]'))
ALTER TABLE [Monkey_Coders].[Publicaciones] DROP CONSTRAINT [FK_Publicaciones_Visibilidades]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__Publicaci__pub_p__6B509E62]') AND type = 'D')
BEGIN
ALTER TABLE [Monkey_Coders].[Publicaciones] DROP CONSTRAINT [DF__Publicaci__pub_p__6B509E62]
END
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_rol_funcionalidad_Funcionalidades]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[rol_funcionalidad]'))
ALTER TABLE [Monkey_Coders].[rol_funcionalidad] DROP CONSTRAINT [FK_rol_funcionalidad_Funcionalidades]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_rol_funcionalidad_Roles]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[rol_funcionalidad]'))
ALTER TABLE [Monkey_Coders].[rol_funcionalidad] DROP CONSTRAINT [FK_rol_funcionalidad_Roles]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__Roles__rol_habil__6E2D0B0D]') AND type = 'D')
BEGIN
ALTER TABLE [Monkey_Coders].[Roles] DROP CONSTRAINT [DF__Roles__rol_habil__6E2D0B0D]
END
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_rp_pub_id]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Rubros_publicaciones]'))
ALTER TABLE [Monkey_Coders].[Rubros_publicaciones] DROP CONSTRAINT [FK_rp_pub_id]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_rp_rub_id]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Rubros_publicaciones]'))
ALTER TABLE [Monkey_Coders].[Rubros_publicaciones] DROP CONSTRAINT [FK_rp_rub_id]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_Subastas_Publicaciones]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[Subastas]'))
ALTER TABLE [Monkey_Coders].[Subastas] DROP CONSTRAINT [FK_Subastas_Publicaciones]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__Subastas__sub_mo__71FD9BF1]') AND type = 'D')
BEGIN
ALTER TABLE [Monkey_Coders].[Subastas] DROP CONSTRAINT [DF__Subastas__sub_mo__71FD9BF1]
END
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_usuario_rol_Roles]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[usuario_rol]'))
ALTER TABLE [Monkey_Coders].[usuario_rol] DROP CONSTRAINT [FK_usuario_rol_Roles]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[FK_usuario_rol_Usuarios]') AND parent_object_id = OBJECT_ID(N'[Monkey_Coders].[usuario_rol]'))
ALTER TABLE [Monkey_Coders].[usuario_rol] DROP CONSTRAINT [FK_usuario_rol_Usuarios]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__Usuarios__usr_ha__74DA089C]') AND type = 'D')
BEGIN
ALTER TABLE [Monkey_Coders].[Usuarios] DROP CONSTRAINT [DF__Usuarios__usr_ha__74DA089C]
END
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__Usuarios__usr_el__75CE2CD5]') AND type = 'D')
BEGIN
ALTER TABLE [Monkey_Coders].[Usuarios] DROP CONSTRAINT [DF__Usuarios__usr_el__75CE2CD5]
END
GO



--DROP DE TABLAS

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Calificaciones]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Calificaciones]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Clientes]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Clientes]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Compras]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Compras]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Empresas]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Empresas]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Estados_publicaciones]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Estados_publicaciones]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Facturas]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Facturas]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Funcionalidades]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Funcionalidades]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Item_factura]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Item_factura]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Ofertas_subasta]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Ofertas_subasta]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Preguntas]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Preguntas]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Publicaciones]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Publicaciones]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[rol_funcionalidad]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[rol_funcionalidad]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Roles]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Roles]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Rubros]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Rubros]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Rubros_publicaciones]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Rubros_publicaciones]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Subastas]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Subastas]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[usuario_rol]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[usuario_rol]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Usuarios]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Usuarios]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Monkey_Coders].[Visibilidades]') AND type in (N'U'))
DROP TABLE [Monkey_Coders].[Visibilidades]
GO